﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using TouchRC.Logic;
using System.Drawing;

namespace TouchRC.Custom_Controls
{
    public class MetadataDescriptionPanel : AdjustablePanel
    {
        #region Private Members

        private List<TouchButton> m_Buttons = new List<TouchButton>();
        private bool m_ShowPlayButton = true;

        #endregion

        protected override void InitControl()
        {
            base.InitControl();
            base.HeightChanged += new EventHandler(MetadataDescriptionPanel_HeightChanged);

            if (m_ShowPlayButton)
            {
                TouchButton playButton = new TouchButton();
                playButton.Image = ImageFactory.GetIImageImageType(ImageTypes.metadata_play);
                playButton.Click += new EventHandler(playButton_Click);
                playButton.Visible = true;
                m_Buttons.Add(playButton);
                Controls.Add(playButton);
            }
        }

        void MetadataDescriptionPanel_HeightChanged(object sender, EventArgs e)
        {
            PositionButtons();
        }

        public event EventHandler PlayClick;

        void playButton_Click(object sender, EventArgs e)
        {
            if (PlayClick != null) PlayClick(sender, e);
        }

        public void PositionButtons()
        {
            if (m_ShowPlayButton)
            {
                if (m_Buttons.Count > 5)
                    throw new Exception("Too many options, I can't handle that many!!");

                int screenWidth = AppSettings.ScreenResolution.Width;
                int buttonDim = AppSettings.ButtonDimensions;
                int screenHeight = UnscaleY(Height);

                //int numberOfButtons = m_Buttons.Count;
                int margin = 10;
                int xPos = margin;
                int yPos = screenHeight - (buttonDim + margin);

                int centreXCoord = (screenWidth - buttonDim) / 2;

                TouchButton button = m_Buttons[0] as TouchButton;
                button.Bounds = new Rectangle(button.ScaleX(centreXCoord), button.ScaleY(yPos),
                                        button.ScaleX(buttonDim), button.ScaleY(buttonDim));
            }

            //if (m_Buttons.Count > 0)
            //{
            //    int totalSpareSpace = screenWidth - (numberOfButtons * buttonDim) - (2 * margin);
            //    int buttonGap = totalSpareSpace / (numberOfButtons);

            //    for (int i = 1; i < numberOfButtons; i++) //(TouchButton button in m_Buttons)
            //    {
            //        xPos += (buttonGap + buttonDim);

            //        TouchButton button = m_Buttons[i] as TouchButton;
            //        button.Bounds = new Rectangle(button.ScaleX(xPos), button.ScaleY(yPos),
            //                                button.ScaleX(buttonDim), button.ScaleY(buttonDim));

            //    }
            //}
        }

        public bool ShowPlayButton
        {
            get { return m_ShowPlayButton; }
            set { m_ShowPlayButton = value; }
        }
    }
}
